# Contributor: Kaarle Ritvanen <kunkku@alpinelinux.org>
# Maintainer: Kaarle Ritvanen <kunkku@alpinelinux.org>
pkgname=awall
pkgver=1.12.2
pkgrel=1
pkgdesc="Alpine Wall"
url="https://gitlab.alpinelinux.org/alpine/awall"
_luaver=5.4
arch="noarch"
license="GPL-2.0-only"
replaces="awall-nat"
depends="drill ipset iptables lua$_luaver lua$_luaver-alt-getopt
	lua$_luaver-cjson lua$_luaver-pc lua$_luaver-posix lua-schema
	lua$_luaver-stringy lua$_luaver-lyaml xtables-addons"
subpackages="$pkgname-masquerade $pkgname-policies"
triggers="$pkgname.trigger=/usr/share/awall"
source="https://gitlab.alpinelinux.org/alpine/awall/-/archive/v$pkgver/awall-v$pkgver.tar.bz2
	awall-init
	setup-firewall
	"
builddir=$srcdir/awall-v$pkgver

build() {
	sed -i -e "1,1s:lua:lua$_luaver:" awall-cli
}

check() {
	make LUA_VERSION=$_luaver check
}

package() {
	make "ROOT_DIR=$pkgdir" LUA_VERSION=$_luaver install
	install -D "$srcdir"/awall-init "$pkgdir"/usr/libexec/awall-init
}

masquerade() {
	depends=awall
	for file in lua/$_luaver/awall/modules/masquerade.lua awall/mandatory/masquerade.json; do
		local path=usr/share/$file
		install -d "$subpkgdir/$(dirname $path)"
		mv "$pkgdir/$path" "$subpkgdir/$path"
	done
}

policies() {
	depends=awall
	local dir=usr/share/awall/optional
	install -d "$subpkgdir"/$dir
	mv "$pkgdir"/$dir/*.json "$subpkgdir"/$dir
	install -D "$srcdir"/setup-firewall "$subpkgdir"/usr/sbin/setup-firewall
}

sha512sums="
0ffc786cf78de2e127671eb7fde3f9f5127c2ffc6d1d9341a16ad19a22d44c62599d2e8459a1d0e7ba379bb8d2574b8c0e7b921356bab3b0ec4f0bd556ad432b  awall-v1.12.2.tar.bz2
e83ea3281c298092530e45fa5b62f6f85b9e5109b11e109799465ea832608294c7d9c4c3f5b0f321dfc0e82040daf3a17d066e9dea65cb0dbae2c453ea9e62cd  awall-init
3a444b0bff5d36c504bc98e71687319778a037240b1170fa7f0bc534d19b3c41a3e4e871a3e3c27304a934e6c2d6b1cd589586a01250244394d014dc858606d9  setup-firewall
"
